package com.ht.dao.impl;


import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ht.dao.StaffDAO;
import com.ht.util.BaseDAO;
import com.ht.util.GetConnection;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;


public class StaffDAOImpl extends BaseDAO implements StaffDAO {
	GetConnection connection = new GetConnection();
	Statement st =null;
	Connection  con  =null;
	
	public List findStaff(String queryString) {
		System.out.println("sql="+queryString);
		List list = new ArrayList();
		 try {
			 con=connection.getCon();
			 st = (Statement) con.createStatement();
			ResultSet rs =st.executeQuery(queryString);
			list = resultSetToList(rs);
			} catch (Exception e) {			
				e.printStackTrace();
			}    
		return list;
	}

	public static List resultSetToList(ResultSet rs) throws java.sql.SQLException {   
        if (rs == null)   
            return Collections.EMPTY_LIST;   
        ResultSetMetaData md = rs.getMetaData(); //得到结果集(rs)的结构信息，比如字段数、字段名等   
        int columnCount = md.getColumnCount(); //返回此 ResultSet 对象中的列数   
        List list = new ArrayList();   
        Map rowData = new HashMap();   
        while (rs.next()) {   
         rowData = new HashMap(columnCount);   
         for (int i = 1; i <= columnCount; i++) {   
                 rowData.put(md.getColumnName(i), rs.getObject(i));   
         }   
         list.add(rowData);   
        }   
        return list;   
	} 
	
	
	
}
